from configparser import ConfigParser
html = '''<!DOCTYPE html>
    <html lang="zh-cn" charset="utf-8">
    <head>
    <title>黄宏哲 | 工作站</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta content="text/html; charset=utf-8" http-equiv="content-type" />
    <script src="https://cdn.staticfile.org/clipboard.js/2.0.4/clipboard.min.js"></script>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <link href="css/default.css" rel="stylesheet" />
    <link href="css/github.css" rel="stylesheet" />
    <link href="css/cp_button.css" rel="stylesheet" />
  </head>
    <body>
    %s
    </body>
    </html>
<script>
  // 定义一个容器，用于存放elment对象
  elements = new Object(); //key:value id:element

  // 添加元素(复制按钮)
  var element;
  // 循环取值
  var items = document.querySelectorAll("pre");
  for (var i = 0; i < items.length; i++) {
    element = items[i];
    elements[i] = element;
    element.insertAdjacentHTML(
      "afterbegin",
      '<button id="copyInput' + i + '">复制</button>'
    );
  }

  function method(id, element) {
    var test = document.getElementById("#copyInput" + id);

    new ClipboardJS("#copyInput" + id, {
      text: function (trigger) {
        return element.getElementsByTagName("code")[0].textContent;
      },
    })
      .on("success", function (e) {
        alert("复制成功！");
        e.clearSelection();
      })
      .on("error", function (e) {
        alert("Error!");
      });
  }

  for (var i = 0; i < items.length; i++) {
    method(i, elements[i]);
  }
</script>
    '''

cfg = ConfigParser()
cfg.read("config.ini",encoding='gbk')
data = dict(cfg.items("article"))
html = html.replace('黄宏哲 | 工作站', data['title'])
